﻿using System;
using System.Linq;
using System.Linq.Expressions;
using System.Linq.Dynamic;using System.Text;
using System.Data.Linq;
using System.Transactions;
using LinqToSqlExtensions;using System.ServiceModel;
using System.Collections;
using System.Collections.Generic;
using CardsServer.DAL;

namespace CardsServer.WCF
{
	public partial interface IService
{
[OperationContract]
string whd_d_fk_Add(whd_d_fk model ,int ACID);


[OperationContract]
string whd_d_fk_Update(whd_d_fk model ,int ACID);


[OperationContract]
string whd_d_fkBydid_Delete(int did,int ACID);


[OperationContract]
whd_d_fk whd_d_fkBydid_Get(int did,int ACID );


[OperationContract]
List<whd_d_fk> whd_d_fk_Get(string sortBy,int ACID);




}
public partial class Service : IService
{
#region  添加whd_d_fk表数据
/// <summary>
/// 添加whd_d_fk
/// </summary>
/// <param name="model">whd_d_fk实体</param>
/// <returns>空或错误</returns>
public string whd_d_fk_Add(whd_d_fk model,int ACID)
{
if(model.did==null )
{
return "『外乎单明细ID』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.whd_d_fk.Count(p=>p.did==model.did)>0)
{
return "主键已存在！";
}
ctx.whd_d_fk.InsertOnSubmit(model);
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 添加失败!错误详细信息：" + ex.Message;
}
}
}
#endregion

#region  添加whd_d_fk表数据事物用重构
/// <summary>
/// 添加whd_d_fk事物用重构
/// </summary>
/// <param name="model">whd_d_fk实体</param>
/// <returns>空或错误</returns>
private string whd_d_fk_Add(whd_d_fk model,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
if(model.did==null )
{
return "『外乎单明细ID』不能为空！";
}
if(ctx.whd_d_fk.Count(p=>p.did==model.did)>0)
{
return "主键已存在！";
}
ctx.whd_d_fk.InsertOnSubmit(model);
return string.Empty;
}
#endregion



#region  修改whd_d_fk表数据
/// <summary>
/// 修改whd_d_fk
/// </summary>
/// <param name="model">whd_d_fk实体</param>
/// <returns>空或错误</returns>
public string whd_d_fk_Update(whd_d_fk model,int ACID)
{
if(model.did==null )
{
return "『外乎单明细ID』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.whd_d_fk.Count(p=>p.did==model.did)!= 1)
{
return "未找到指定记录或记录不唯一！";
}
whd_d_fk whd_d_fkmodel=ctx.whd_d_fk.Single(p => p.did==model.did);
if(model.did!=null )
{
whd_d_fkmodel.did=model.did;
}
if(!string.IsNullOrEmpty(model.jrh))
{
whd_d_fkmodel.jrh=model.jrh;
}
if(!string.IsNullOrEmpty(model.linktel))
{
whd_d_fkmodel.linktel=model.linktel;
}
if(!string.IsNullOrEmpty(model.ytc))
{
whd_d_fkmodel.ytc=model.ytc;
}
if(!string.IsNullOrEmpty(model.xtc))
{
whd_d_fkmodel.xtc=model.xtc;
}
if(model.yysj!=null )
{
whd_d_fkmodel.yysj=model.yysj;
}
if(model.skje!=null )
{
whd_d_fkmodel.skje=model.skje;
}
if(!string.IsNullOrEmpty(model.fkAdd))
{
whd_d_fkmodel.fkAdd=model.fkAdd;
}
if(!string.IsNullOrEmpty(model.bzzp))
{
whd_d_fkmodel.bzzp=model.bzzp;
}
if(!string.IsNullOrEmpty(model.fkjg))
{
whd_d_fkmodel.fkjg=model.fkjg;
}
if(!string.IsNullOrEmpty(model.fksm))
{
whd_d_fkmodel.fksm=model.fksm;
}
if(model.whr!=null || model.whr.Equals(Guid.Empty))
{
whd_d_fkmodel.whr=model.whr;
}
if(model.sdr!=null || model.sdr.Equals(Guid.Empty))
{
whd_d_fkmodel.sdr=model.sdr;
}
if(model.ssje!=null )
{
whd_d_fkmodel.ssje=model.ssje;
}
if(!string.IsNullOrEmpty(model.sdbz))
{
whd_d_fkmodel.sdbz=model.sdbz;
}
if(!string.IsNullOrEmpty(model.fspff))
{
whd_d_fkmodel.fspff=model.fspff;
}
if(model.ldjfje!=null )
{
whd_d_fkmodel.ldjfje=model.ldjfje;
}
if(!string.IsNullOrEmpty(model.gdbz))
{
whd_d_fkmodel.gdbz=model.gdbz;
}
if(!string.IsNullOrEmpty(model.xcclshj))
{
whd_d_fkmodel.xcclshj=model.xcclshj;
}
if(model.ldr!=null || model.ldr.Equals(Guid.Empty))
{
whd_d_fkmodel.ldr=model.ldr;
}
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 修改失败!错误详细信息：" + ex.Message;
}
}
}
#endregion



#region  删除whd_d_fk表Bydid数据
/// <summary>
/// 删除whd_d_fkBydid
/// </summary>
/// <param name="did">外乎单明细ID</param>
/// <returns>空或错误</returns>
public string whd_d_fkBydid_Delete(int did,int ACID)
{
if(did==null )
{
return "『外乎单明细ID』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.whd_d_fk.Count(p=>p.did==did)!=1)
{
return null;
}
whd_d_fk model=ctx.whd_d_fk.Single(p => p.did== did);
ctx.whd_d_fk.DeleteOnSubmit(model);
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 删除失败!错误详细信息：" + ex.Message;
}
}
}
#endregion

#region  删除whd_d_fk表Bydid数据[事物用重构]
/// <summary>
/// 删除whd_d_fkBydid[事物用重构]
/// </summary>
/// <param name="did">外乎单明细ID</param>
/// <returns>空或错误</returns>
private string whd_d_fkBydid_Delete(int did,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
if(did==null )
{
return "『外乎单明细ID』不能为空！";
}
if(ctx.whd_d_fk.Count(p=>p.did==did)!=1)
{
return null;
}
whd_d_fk model=ctx.whd_d_fk.Single(p => p.did== did);
ctx.whd_d_fk.DeleteOnSubmit(model);
return string.Empty;
}
#endregion



#region  获取whd_d_fk表Bydid数据
/// <summary>
/// 获取whd_d_fkBydid
/// </summary>
/// <param name="did">外乎单明细ID</param>
/// <returns>当前表</returns>
public whd_d_fk whd_d_fkBydid_Get(int did,int ACID)
{
if(did==null )
{
return null;
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.whd_d_fk.Count(p=>p.did==did)!=1)
{
return null;
}
return ctx.whd_d_fk.SingleOrDefault(p=>p.did==did);
}
catch (Exception ex)
{
return null;
}
}
}
#endregion



#region  获取whd_d_fk表数据
/// <summary>
/// 获取whd_d_fk
/// </summary>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<whd_d_fk></returns>
public List<whd_d_fk> whd_d_fk_Get(Expression<Func<whd_d_fk, bool>> predicate , string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.whd_d_fk.ToList();
}
 else 
{
return ctx.whd_d_fk.OrderBy(sortBy).ToList();
}
}
else
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.whd_d_fk.Where(predicate).ToList();
}
 else 
{
return ctx.whd_d_fk.Where(predicate).OrderBy(sortBy).ToList();
}
}
}
catch (Exception ex)
{
return null;
}
}
}
#endregion


#region  获取whd_d_fk表数据
/// <summary>
/// 获取whd_d_fk
/// </summary>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<whd_d_fk></returns>
public List<whd_d_fk> whd_d_fk_Get(string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
return whd_d_fk_Get(null,sortBy, ACID);
}
catch (Exception)
{
return null;
}
}
}
#endregion


#region  获取whd_d_fk表数据计数
/// <summary>
/// 获取whd_d_fk表数据计数
/// </summary>
/// <returns>List<whd_d_fk></returns>
public int whd_d_fk_GetCount(Expression<Func<whd_d_fk, bool>> predicate,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
return ctx.whd_d_fk.Count();

}
 else
{
return ctx.whd_d_fk.Where(predicate).Count();
}
}
catch 
{
return 0;
}
}
}
#endregion




#region  获取whd_d_fk分页表数据
/// <summary>
/// 获取whd_d_fk分页表数据
/// </summary>
/// <param name="pageIndex">当前页</param>
/// <param name="pageSize">页大小</param>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<whd_d_fk></returns>
public List<whd_d_fk> whd_d_fk_Getpage(int pageIndex, int pageSize,Expression<Func<whd_d_fk, bool>> predicate ,string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.whd_d_fk.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
 else 
{
return ctx.whd_d_fk.OrderBy(sortBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
}
else
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.whd_d_fk.Where(predicate).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
 else 
{
return ctx.whd_d_fk.Where(predicate).OrderBy(sortBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
}
}
catch (Exception ex)
{
return null;
}
}
}
#endregion


#region  批量修改whd_d_fk表数据
/// <summary>
/// 批量修改whd_d_fk
/// </summary>
/// <param name="predicate">Expression<Func<whd_d_fk, bool>></param> 查找表达式树
/// <param name="updater">Expression<Func<whd_d_fk,whd_d_fk>> 更新表达式树</param>
/// <param name="returns">影响记录数</param>
public int whd_d_fk_batchUpdate(Expression<Func<whd_d_fk, bool>> predicate,Expression<Func<whd_d_fk, whd_d_fk>> updater,int ACID)
{
using (TransactionScope ts=new TransactionScope())
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
int ok = ctx.whd_d_fk.Update(predicate, updater);
ts.Complete();
 return ok;
}
catch (Exception ex)
{
return 0;
}
}
}
}
#endregion


#region  批量修改whd_d_fk表数据事物用重构
/// <summary>
/// 批量修改whd_d_fk事物用重构
/// </summary>
/// <param name="predicate">Expression<Func<whd_d_fk, bool>></param> 查找表达式树
/// <param name="updater">Expression<Func<whd_d_fk,whd_d_fk>> 更新表达式树</param>
/// <param name="ctx">数据上下文</param>
/// <param name="returns">影响记录数</param>
private int whd_d_fk_batchUpdate(Expression<Func<whd_d_fk, bool>> predicate,Expression<Func<whd_d_fk, whd_d_fk>> updater,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
int ok = ctx.whd_d_fk.Update(predicate, updater);
return ok;
}
#endregion


#region  批量删除whd_d_fk表数据
/// <summary>
/// 批量删除whd_d_fk
/// </summary>
/// <param name="predicate">Expression<Func<whd_d_fk, bool>></param> 查找表达式树
/// <param name="returns">影响记录数</param>
public int whd_d_fk_batchDel(Expression<Func<whd_d_fk, bool>> predicate,int ACID)
{
using (TransactionScope ts=new TransactionScope())
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
int ok = ctx.whd_d_fk.Delete(predicate);
ts.Complete();
 return ok;
}
catch (Exception ex)
{
return 0;
}
}
}
}
#endregion


#region  批量删除whd_d_fk表数据事物用重构
/// <summary>
/// 批量删除whd_d_fk事物用重构
/// </summary>
/// <param name="predicate">Expression<Func<whd_d_fk, bool>></param> 查找表达式树
/// <param name="ctx">数据上下文</param>
/// <param name="returns">影响记录数</param>
private int whd_d_fk_batchDel(Expression<Func<whd_d_fk, bool>> predicate,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
int ok = ctx.whd_d_fk.Delete(predicate);
return ok;
}
#endregion


}
}

